/*
** Summary - Creates an sliding effect for an image gallery. To use create a new instance of the Accordian object.
**
** leftSelector, rightSelector  : jquery selector pointing to the left and right buttons
** scrollerSelector 			: jquery selector for the scrolling element
** imageWidth					: width of each image in the gallery - should include outer space like margins etc.
** imageCount					: number of images in the gallery
** options						: optional params object to enable/disable scroll buttons - leftClickHide, leftClickShow, rightClickHide, rightClickShow
*/

function Accordion(leftSelector, rightSelector, scrollerSelector, imageWidth, imageCount, pageSize, options) {
    "use strict";
    
    var _page = 0;
    var _scrollAmount = imageWidth * pageSize;
    var _pageCount = parseInt(imageCount / pageSize);

    // Setup left scroll functionality
    $(leftSelector).click(function () {
        options.rightClickShow();

        if (_page > 0) {
            _page--;
            $(scrollerSelector).animate({ left: "+=" + _scrollAmount });
            if (_page === 0) options.leftClickHide();
        }
    });

    // Setup right scroll functionality
    $(rightSelector).click(function () {
        options.leftClickShow();

        if(_page < _pageCount) {
            _page++;
            $(scrollerSelector).animate({ left: "-=" + _scrollAmount });
            if(_page === _pageCount) options.rightClickHide();
        }
    });

    // Create blank methods for missing optional parameters
    if(options) {
        var opts = ["leftClickHide", "leftClickShow","rightClickHide", "rightClickShow"];

        for (var count = 0; count < opts.length; count++)
            if (typeof options[opts[count]] === "undefined")
                options[opts[count]] = {};
    }

    // Setup the gallery
    options.leftClickHide();
    if (_page === _pageCount) options.rightClickHide();
    $(scrollerSelector).width(imageCount * imageWidth);
}